/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Model;
import de.trantor.mail.*;



/**
 *
 * @author Pisarchik_S
 */
public class SendEmail {

    public SendEmail(CModel model, EMailSettings settings)
    {
        m_model = model;
        m_EmailsSettings = settings;
    }

    CModel m_model;
    EMailSettings m_EmailsSettings;

    public void Send()
    {
        try
        {
            Message message = new Message(m_EmailsSettings.m_sUserName, m_EmailsSettings.m_sRecipient, "MoneyTracker report");
            String s = "Content-Type:text/plain; charset=\"UTF-8\"";
            message.addHeaderLine(s);
            s = "Content-Transfer-Encoding:quoted-printable";
            message.addHeaderLine(s);
            message.addBodyLine(m_model.GetString());


            SmtpClient smtpClient = null; // use proxy:
            // smtpClient = new SmtpClient(
            // new de.trantor.mail.http.ConnectionImpl(
            // httpHost, 8080), hostname);
            smtpClient = new SmtpClient("localhost");
            smtpClient.open(m_EmailsSettings.m_sSMTPServer, m_EmailsSettings.m_port, false, m_EmailsSettings.m_sUserName, m_EmailsSettings.m_sPassword);
            smtpClient.sendMessage(message);
            smtpClient.close();
            smtpClient = null;
        }
        catch(MailException e)
        {
            String s = e.getMessage();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }


}
